//
//  SJLoginVC.m
//  SJPay
//
//  Created by 凯朱 on 2024/11/23.
//

#import "SJLoginVC.h"
#import "SJGetCodeVC.h"


@interface SJLoginVC ()

@end

@implementation SJLoginVC
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpUI];
}

- (IBAction)sureAction:(id)sender {
    
    if (_tf.text.length == 0) {
        kShowToast(@"输入手机号码");
        return;
    }
    NSDictionary *params = @{@"phone":_tf.text};
    [ZCTool showHudOnView:self.view];
    [ZKHttpManager postWithPath:@"login/captcha" params:params finished:^(BOOL isSuccessed, id result, NSString *code, NSString *message) {
        [ZCTool hideHudOnView:self.view];
        if (!isSuccessed) {
            kShowToast(message);
            return;
        }
        SJGetCodeVC *vc = [[SJGetCodeVC alloc] init];
        vc.tel = self->_tf.text;
        [self.navigationController pushViewController:vc animated:YES];
    }];
}

-(void)setUpUI{
    _bgView1.layer.cornerRadius = 15;
    _bgView1.layer.masksToBounds = YES;
    _bgView2.layer.cornerRadius = 15;
    _bgView2.layer.masksToBounds = YES;
    _sureBtn.layer.cornerRadius = 25;
    _sureBtn.layer.masksToBounds = YES;
    _topLbl.text = kLocalString(@"Fácil Préstamo");
    _titleLbl.text = kLocalString(@"用户名");
    _tipLbl.text = kLocalString(@"正规金融机构");
    [_tf setPlaceholder:kLocalString(@"请输入您的手机号码")];
    [_sureBtn setTitle:kLocalString(@"获取验证码") forState:UIControlStateNormal];
    
    NSString *textStr = kLocalString(@"登录即代表你同意 服务条款 和 隐私权政策");
    __block NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:textStr];
    text.color = KColor_1;
    NSRange range = [textStr rangeOfString:kLocalString(@"服务条款")];
    [text setTextHighlightRange:range color:KColor_B backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull clickText, NSRange range, CGRect rect) {
        RootWebViewController *vc = [RootWebViewController new];
        vc.url = @"https://www.baidu.com";
        [self.navigationController pushViewController:vc animated:YES];
    }];
    
    NSRange range2 = [textStr rangeOfString:kLocalString(@"隐私权政策")];
    [text setTextHighlightRange:range2 color:KColor_B backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull clickText, NSRange range, CGRect rect) {
        RootWebViewController *vc = [RootWebViewController new];
        vc.url = @"https://www.baidu.com";
        [self.navigationController pushViewController:vc animated:YES];
    }];
   
    YYLabel *textLabel = [YYLabel new];
    text.font = kFont(12);
    text.lineSpacing = 3;
    textLabel.numberOfLines = 0;
    textLabel.attributedText = text;
    //设置换行方式
    NSMutableParagraphStyle  *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 3;
    text.paragraphStyle = paragraphStyle;
    
    //计算文本尺寸
    CGSize maxSize = CGSizeMake(KScreenWidth-70, MAXFLOAT);
    YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:maxSize text:text];
    textLabel.textLayout = layout;
    CGFloat introHeight = layout.textBoundingSize.height;
    textLabel.width = maxSize.width;
    textLabel.height = introHeight;
    textLabel.left = (KScreenWidth-textLabel.width)/2;
    [_proBgView addSubview:textLabel];
    
//    _tf.text = @"8863453453";
}

- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
